// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
// Adds the .js mime to URLs, so that Rails fires the correct respond_to response.
var mimeifyUrl = function(url){
	if (/\.js/.test(url)){
		return url
	} else if (/\?/.test(url)) {
		return url.replace('?', '.js?')
	} else {
		return url + '.js'
	}
}

$.ajaxSetup({
	complete: function(response, status){
		$('#loading_indicator').hide()
	},
	error: function(){
		alert('An error occured!') // replace this with your own awesome error handler
	},
	beforeSend: function(request, params){
		$('#loading_indicator').show()
	}
});

// Similar to the built in 'load' function in jQuery, extended so that it adds the .js mime to
// the url.
$.fn.railsLoad = function(location){
  var self = this;
  $.ajax({
    url: mimeifyUrl(location),
    success: function(response, status){
      $(self).html(response);
    }
  });
}
$.fn.railsLoad_js = function(location){
  $.ajax({
    url: location,
    dataType:"script",
    type:'get'
  });
}


